package com.example.employeemanagement.mapper;

import com.example.employeemanagement.entry.Employee;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Optional;

@Mapper
public interface EmployeeMapper {
    @Select("SELECT * FROM employee")
    List<Employee> getAllEmployees();

    @Insert("INSERT INTO employee (first_name, last_name, email, phone_number, hire_date, position_id, salary, username, password, roleId, department_id, avator) VALUES (#{first_name}, #{last_name}, #{email}, #{phone_number}, #{hire_date}, #{position_id}, #{salary}, #{username}, #{password}, #{roleId}, #{department_id}, #{avator})")
    int addEmployee(Employee employee);

    @Select("SELECT * FROM employee WHERE employee_id = #{id}")
    Optional<Employee> getEmployeeById(@Param("id") Integer id);

    @Select("SELECT * FROM employee WHERE username = #{username}")
    Employee findUserByUserName(String username);

    @Update("UPDATE employee SET username = #{updatedEmployee.username}, email = #{updatedEmployee.email}, phone_number = #{updatedEmployee.phone_number}, avator = #{updatedEmployee.avator} WHERE employee_id = #{id}")
    int updateEmployee(@Param("id") Integer id, @Param("updatedEmployee") Employee updatedEmployee);
    
    @Update("UPDATE employee SET avator = #{avatarPath} WHERE employee_id = #{employeeId}")
    int updateEmployeeAvatar(@Param("employeeId") Integer employeeId, @Param("avatarPath") String avatarPath);

    @Delete("DELETE FROM employee WHERE employee_id = #{id}")
    int deleteEmployee(@Param("id") Integer id);
}